﻿<Window x:Class="IconMaker.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ms="clr-namespace:Microsoft.Win32;assembly=PresentationFramework"
        Title="Icon Maker" Icon="IconMaker.ico" Height="500" Width="320" MinWidth="300" MinHeight="300" AllowDrop="True">
    <Window.Resources>
        <Style x:Key="sizeStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="FontStyle" Value="Italic" />
            <Setter Property="FontSize" Value="11" />
        </Style>
        <ms:OpenFileDialog x:Key="importDialog" Filter="Image files (*.png,*.bmp,*.gif,*.jpg)|*.png;*.bmp;*.gif;*.jpg|All files (*.*)|*.*" Multiselect="True" />
        <ms:SaveFileDialog x:Key="saveDialog" Filter="Icon files (*.ico)|*.ico" DefaultExt="ico" />
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="New" CanExecute="CommandAlwaysCanExecute" Executed="NewExecuted" />
        <CommandBinding Command="Open" CanExecute="CommandAlwaysCanExecute" Executed="OpenExecuted" />
        <CommandBinding Command="Save" CanExecute="SaveCanExecute" Executed="SaveExecuted" />
        <CommandBinding Command="Close" CanExecute="CommandAlwaysCanExecute" Executed="CloseExecuted" />
        <CommandBinding Command="Cut" CanExecute="CanExecuteIfSelected" Executed="CutExecuted" />
        <CommandBinding Command="Copy" CanExecute="CanExecuteIfSelected" Executed="CopyExecuted" />
        <CommandBinding Command="Paste" CanExecute="PasteCanExecute" Executed="PasteExecuted" />
        <CommandBinding Command="Delete" CanExecute="CanExecuteIfSelected" Executed="DeleteExecuted" />
    </Window.CommandBindings>
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Command="New" />
                <Separator />
                <MenuItem Header="_Import Images..." Command="Open" />
                <MenuItem Header="_Save Icon..." Command="Save" />
                <Separator />
                <MenuItem Header="E_xit" Command="Close" />
            </MenuItem>
            <MenuItem Header="_Edit">
                <MenuItem Command="Cut" />
                <MenuItem Command="Copy" />
                <MenuItem Command="Paste" />
                <MenuItem Command="Delete" />
            </MenuItem>
        </Menu>
        <Grid>
            <ListBox Name="imageList" HorizontalContentAlignment="Stretch">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel HorizontalAlignment="Stretch" Margin="0,3">
                            <Image Stretch="Fill" Source="{Binding}" HorizontalAlignment="Center"
                                   Width="{Binding Path=PixelWidth}" Height="{Binding Path=PixelHeight}" />
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                <TextBlock Text="{Binding Path=PixelWidth}" Style="{StaticResource sizeStyle}" />
                                <TextBlock Text="x" Style="{StaticResource sizeStyle}" />
                                <TextBlock Text="{Binding Path=PixelHeight}" Style="{StaticResource sizeStyle}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <Border Background="Transparent" CornerRadius="4" BorderThickness="1" x:Name="itemBorder" Margin="0,1">
                                        <ContentPresenter />
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="itemBorder" Property="Background">
                                                <Setter.Value>
                                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                                        <GradientStop Color="#DCEBFC" Offset="0" />
                                                        <GradientStop Color="#CDE2FC" Offset="0.5" />
                                                        <GradientStop Color="#C1DBFC" Offset="1" />
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter TargetName="itemBorder" Property="BorderBrush" Value="CornflowerBlue" />
                                        </Trigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsSelected" Value="False" />
                                                <Condition Property="IsMouseOver" Value="True" />
                                            </MultiTrigger.Conditions>
                                            <Setter TargetName="itemBorder" Property="Background">
                                                <Setter.Value>
                                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1" Opacity="0.25">
                                                        <GradientStop Color="#DCEBFC" Offset="0" />
                                                        <GradientStop Color="#CDE2FC" Offset="0.5" />
                                                        <GradientStop Color="#C1DBFC" Offset="1" />
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter TargetName="itemBorder" Property="BorderBrush">
                                                <Setter.Value>
                                                    <SolidColorBrush Color="CornflowerBlue" Opacity="0.25" />
                                                </Setter.Value>
                                            </Setter>
                                        </MultiTrigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="Cut" />
                        <MenuItem Command="Copy" />
                        <MenuItem Command="Paste" />
                        <MenuItem Command="Delete" />
                    </ContextMenu>
                </ListBox.ContextMenu>
            </ListBox>
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontStyle="Italic"
                       Margin="4" TextWrapping="Wrap"
                       Text="Drag image files here, or import them using the menu.">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=imageList, Path=HasItems}" Value="True">
                                <Setter Property="TextBlock.Visibility" Value="Collapsed" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </Grid>
    </DockPanel>
</Window>
